package com.prothink.threadproject.util;

import cn.hutool.core.util.RandomUtil;
import org.apache.commons.lang3.RandomUtils;

public class PwdUtil {
    /**
     * 生成一个随机的密码: 数字+字母组合,长度为6
     * a-z 大写小
     * 0-9: >=1 <=5
     * 长度为6
     */
    public static String generatorPassword(){
        String password = "";
        //numSize是
        int numSize = RandomUtils.nextInt(1, 6);
        System.out.println("数字密码的数量: " + numSize);
        for (int i = 0; i < numSize; i++) {
            int num = RandomUtils.nextInt(0,10);
            System.out.println(num);
        }
        int charNum = 6 - numSize;
        System.out.println("字母的密码的长度: " + charNum);
        for (int i = 0; i < charNum; i++) {
            int num = RandomUtils.nextInt(0,26);
            char randomChar;
            if (RandomUtils.nextInt(0,2) != 0){
                //小写
                randomChar = (char) ('a' + num);
            }else {
                //大写
                randomChar = (char) ('A' + num);
            }
            password += randomChar;
        }
        System.out.println(password);
        return password;
    }

    public static void main(String[] args) {
        PwdUtil.generatorPassword();
    }
}
